﻿using System;
using System.IO;
using System.Linq;

namespace MsTestUtilities.SolutionAnalysis.Testing
{
    public static class SolutionAssert
    {
        public static SolutionFile Solution { get; private set; }

        private static SolutionAsserter _solutionAsserter;

        public static void SetSolutionFile(string solutionPath)
        {
            _solutionAsserter = ForSolutionFile(solutionPath);
        }

        public static void SetSolutionFromSolutionInfoFile()
        {
            _solutionAsserter = ForThisSolution();
        }

        public static SolutionAsserter ForSolutionFile(string solutionPath)
        {
            var reader = new SolutionFileReader();
            
            var solutionInfo = reader.ReadFromFile(solutionPath);

            Solution = SolutionFile.LoadFromInfo(solutionInfo);
            return new SolutionAsserter(Solution);
        }

        private static SolutionAsserter ForThisSolution()
        {
            var solutionPath = File.ReadLines(@"SolutionInfo\SolutionPath.txt").First();
            return ForSolutionFile(solutionPath);        
        }

        public static ProjectAssert ForAllProjects()
        {
            return _solutionAsserter.ForAllProjects();
        }

        public static ProjectAssert ForAllProjects(Predicate<CsProject> predicate)
        {
            return _solutionAsserter.ForAllProjects(predicate);
        }
        
        public static ProjectAssert ForTestProjects()
        {
            return _solutionAsserter.ForTestProjects();
        }

        public static ProjectAssert ForNonTestProjects()
        {
            return _solutionAsserter.ForNonTestProjects();
        }       
    }
}
